From 9ced0ad0085de51f273c809c407861b5582c6765 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 9 Apr 2001 10:52:43 +0000 Subject: [PATCH] (align): If the argument SIZE would overflow __malloc_ptrdiff_t, fail right away. --- src/gmalloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gmalloc.c b/src/gmalloc.c index 751e90baf13..3508304da33 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -437,7 +437,14 @@ align (size) __ptr_t result; unsigned long int adj; - result = (*__morecore) (size); + /* align accepts an unsigned argument, but __morecore accepts a + signed one. This could lead to trouble if SIZE overflows a + signed int type accepted by __morecore. We just punt in that + case, since they are requesting a ludicrous amount anyway. */ + if ((__malloc_ptrdiff_t)size < 0) + result = 0; + else + result = (*__morecore) (size); adj = (unsigned long int) ((unsigned long int) ((char *) result - (char *) NULL)) % BLOCKSIZE; if (adj != 0) -- 2.30.2